package com.se.hospitalmonitoring;

import java.io.Serializable;
import java.text.DecimalFormat;
import java.util.Date;

public class VitalSign implements Serializable {

	private static final long serialVersionUID = 1L;
	public long id = -1L;
	public String name = null;
	public int lowerBound = 0;
	public int upperBound = 100;
	public float scaleFactor = 1;
	public String unitName = null;

	/**
	 * Constructor
	 * 
	 * @param id
	 *            The id of the vital sign
	 * @param name
	 *            The name of the vital sign
	 * @param percentValue
	 *            The value percent of the vital sign
	 * @param lowerBound
	 *            The lower bound in percentages that is safe
	 * @param upperBound
	 *            The upper bound in percentages that is safe
	 * @param unitScaleFactor
	 *            The multiplier for scaling a percentage to real units
	 * @param unitName
	 *            The unit label to be concatenated to values
	 */
	public VitalSign(long id, String name, int lowerBound, int upperBound,
		float unitScaleFactor, String unitName) {
		this.id = id;
		this.name = name;
		this.lowerBound = lowerBound;
		this.upperBound = upperBound;
		this.scaleFactor = unitScaleFactor;
		this.unitName = unitName;
	}

	/**
	 * Sets the range of safe values for this vital sign
	 * 
	 * @param lowerBound
	 *            The lower bound in percentages that is safe
	 * @param upperBound
	 *            The upper bound in percentages that is safe
	 */
	public void setVitalRange(int lowerBound, int upperBound) {
		this.lowerBound = lowerBound;
		this.upperBound = upperBound;
	}

	/**
	 * A class for holding a vital sign an an associated percentage value for an
	 * instantaneous reading
	 */
	public static class VitalSignMeasurement implements Serializable {
		private static final long serialVersionUID = 1L;
		public VitalSign vitalSign = null;
		public int percentValue = -1;
		public Date timestamp = null;

		DecimalFormat formatter = new DecimalFormat("#####");

		/**
		 * Constructor
		 * 
		 * @param vitalSign
		 *            The vital sign for this measurement
		 * @param percentValue
		 *            The value of this measurement
		 */
		public VitalSignMeasurement(VitalSign vitalSign, int percentValue,
			Date timestamp) {
			this.vitalSign = vitalSign;
			this.percentValue = percentValue;
			this.timestamp = timestamp;
		}

		public float getValue() {
			return percentValue * vitalSign.scaleFactor;
		}

		/**
		 * Returns a human-readable string representation of this object
		 * 
		 * @return A human-readable string representation of this object
		 */
		@Override
		public String toString() {
			return formatter.format(getValue()) + vitalSign.unitName;
		}
	}
}
